package com.example.test.chapter10;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.example.test.R;
import com.example.test.app.main.ApplicationMain;
import com.example.test.chapter10.addmennu.OptionsMenuActivity;
import com.example.test.chapter10.contextmenu.ContextMenu2Activity;
import com.example.test.chapter10.contextmenu.ContextMenuAActivity;
import com.example.test.chapter10.menuxml.InflatingMenuActivity;

public class MainChapter10 extends Activity implements OnItemClickListener {
	private String[] sample = new String[] { "10.3 Adding Menu",
			"10.4 Adding Icons ", "10.5 Context Menu",
			"10.6 Context Menu Example 2", "10.7 Menu Example 3 - XML" };
	private int[] _id = new int[] { 1, 2, 3, 4, 5 };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainchapter10);
		ListView listView = (ListView) findViewById(R.id.listViewChapter10);
		listView.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, sample));
		listView.setOnItemClickListener(this);
		Button btn = (Button) findViewById(R.id.backpage);
		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(),
						ApplicationMain.class);
				startActivity(intent);
				finish();
			}
		});
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		switch (_id[arg2]) {
		case 1:
			startActivity(new Intent(this, OptionsMenuActivity.class));
			break;
		case 2:
			startActivity(new Intent(
					this,
					com.example.test.chapter10.addicon.OptionsMenuActivity.class));
			break;
		case 3:
			startActivity(new Intent(this, ContextMenuAActivity.class));
			break;
		case 4:
			startActivity(new Intent(this, ContextMenu2Activity.class));
			break;
		case 5:
			startActivity(new Intent(this, InflatingMenuActivity.class));
			break;
		default:
			break;
		}

	}
}
